<?php
/**
 * 商店模型
 * 
 * @version $Id: Shop.php 492 2012-11-08 09:19:13Z linsir123 $
 */
class modelShop
{
	/**
	 * @var TOP数据请求对象
	 */
	public $top;
	
	/**
	 * 构造函数
	 */
	function __construct()
	{
		$this->top = M::topRequest();
	}
	
	/**
	 * 取得一个
	 */
	public function getOne($nick)
	{
		$data = $this->_getList(array($nick));
		
		///
		return isset($data[0])?$data[0]:array();
	}
	
	/**
	 * 取得关联
	 */
	public function getRelate($nick, $max = 5)
	{
		$i = 0;
		$nicks = array();
		$tmp = $this->top->taobaokeShopsRelateGet(array('sellerNick'=>$nick));
		foreach ($tmp as $v) {
			$nicks[] = $v['seller_nick'];
			if (++$i > $max) 
				break;
		}
		
		///
		return $this->_getList($nicks);
	}
	
	
	/// 以下为私有方法 ///
	
	
	/**
	 * 根据商店Nick取得列表
	 */
	private function _getList($nicks)
	{
		$data = array();
		foreach ($nicks as $v) {
			$v = trim($v);
			if ( ! empty($v)) {
				$shop = $this->top->shopGet($v);
				if (isset($shop['sid'])) {
					if (empty($shop['pic_path'])) 
						$shop['pic_path'] = '';
						
					$data[] = $shop;
				}
			}
		}
		
		/// 
		return $data;
	}
}
